package com.lww.feature.test.design.pattern.prototype;

import java.io.*;

/**
 * @author: liweiwei
 * @date: 2019/1/22
 */
public class DeepCloneHouse extends House  {


    @Override
    public Object clone() throws CloneNotSupportedException {
        ByteArrayOutputStream bo=new ByteArrayOutputStream();
        ObjectOutputStream oo= null;
        try {
            oo = new ObjectOutputStream(bo);
            oo.writeObject(this);
        //从流里读出来
            ByteArrayInputStream bi=new ByteArrayInputStream(bo.toByteArray());
            ObjectInputStream oi=new ObjectInputStream(bi);
            return(oi.readObject());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
